package root.electronclass.electronclass.personal

import android.util.Log
import root.electronclass.electronclass.mvp.GlobalParameter
import root.electronclass.electronclass.mvp.entity.ExamSummary
import root.electronclass.electronclass.mvp.entity.MoralScoreRecord
import root.electronclass.electronclass.mvp.entity.UserPageQuery
import root.electronclass.electronclass.mvp.rest.RestManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 *
 */
object PersonRepository {

    suspend fun examPage(pageIndex: Int, dataType: Int): List<ExamSummary> = withContext(Dispatchers.IO) {
        val baseResponse = RestManager.getInstance().initRest().examPage(
            UserPageQuery(
                GlobalParameter.getEcardInfo().classId.toString(),
                pageIndex,
                20,
                GlobalParameter.getEcardInfo().schoolId.toString(),
                dataType,
                GlobalParameter.getSTUDENT().id.toString()
            )
        )
        baseResponse.rows?.records ?: mutableListOf()
    }

    suspend fun examPage1(pageIndex: Int, dataType: Int, competitionId: Long): List<MoralScoreRecord> =
        withContext(Dispatchers.IO) {
            val record = MoralScoreRecord()
            record.type = dataType
            record.pageNum = pageIndex
            record.studentId = GlobalParameter.getSTUDENT().id
            if (dataType == 4) {
                record.competitionId = competitionId
            }
            Log.i("","examPage:$record")
            val baseResponse = RestManager.getInstance().initRest().examPage(record)
            baseResponse.rows ?: mutableListOf()
        }


}